$(function() {
    dd.ready(function() {
		dd.runtime.permission.requestAuthCode({
			corpId : "dinge91442a6a05c3109ffe93478753d9884", //教育局
			onSuccess : function(result) {
                dingdingLogin(result.code);
			},
			onFail : function(err) {
                alert('dd error: ' + JSON.stringify(err));
            }
		});
	});
});

function dingdingLogin(code) {
    $.ajax({
        url: ctx + "dingding",
        data: {
            "code" : code
        },
        type: "post",
        success: function (r) {
            if (r.code == 200) {
                window.localStorage.setItem("token",r.result.token);
                location.href = ctx + 'index?token=' + window.localStorage.getItem("token");
            } else {
                layer.msg(r.message);
            }
        }
    });
}